<?php

namespace common\models\cms;

use Yii;

/**
 * This is the model class for table "{{%cms_article_comment}}".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property int $article_id 文章ID
 * @property int $comment_id 评论ID
 * @property int $reply_id 回复ID
 * @property string $post 评论内容
 * @property string|null $attach 评论附件
 * @property string|null $author 作者
 * @property string|null $listener 被回复人
 * @property int $likes 点赞数
 * @property int $status 评论状态
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 * @property int $deleted_at 删除时间
 */
class CmsArticleComment extends \common\db\ActiveRecord {

    /**
     * {@inheritdoc}
     */
    public static function tableName() {
        return '{{%cms_article_comment}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules() {
        return [
            [['user_id', 'article_id', 'comment_id', 'reply_id', 'likes', 'status', 'created_at', 'updated_at', 'deleted_at'], 'integer'],
            [['post'], 'required'],
            [['attach'], 'string'],
            [['post'], 'string', 'max' => 1000],
            [['author', 'listener'], 'string', 'max' => 30],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => '用户ID',
            'article_id' => '文章ID',
            'comment_id' => '评论ID',
            'reply_id' => '回复ID',
            'post' => '评论内容',
            'attach' => '评论附件',
            'author' => '作者',
            'listener' => '被回复人',
            'likes' => '点赞数',
            'status' => '评论状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
            'deleted_at' => '删除时间',
        ];
    }

    public function getParent() {
        return $this->hasOne(static::className(), ['id' => 'comment_id']);
    }

    public function getChildren() {
        return $this->hasMany(static::className(), ['comment_id' => 'id']);
    }

    /**
     * 用户基本信息
     * @return user
     */
    public function getUser() {
        return $this->hasOne(\common\models\user\UserMeta::className(), ['id' => 'user_id']);
    }

}
